﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace S
{
    /// <summary>
    /// 单例类
    /// </summary>
    public class Singleton
    {
        /// <summary>
        /// 单例, 私有, 静态, 防止类外访问
        /// </summary>
        private static Singleton _instance;

        /// <summary>
        /// 避免类外实例化, 所以构造函数采用 private,通常的构造函数都是public
        /// </summary>
        private Singleton()
        {

        }

        /// <summary>
        /// 获取当前实例, public共有的,  static静态方法
        /// </summary>
        /// <returns></returns>
        public static Singleton GetInstance()
        {
            if (_instance == null)
            {
                _instance = new Singleton();
            }
            return _instance;
        }
    }
}
